$(function () {
    //添加点击事件
    $('.input_sub').click(function (e) {
        e.preventDefault()
        let username = $('.input_txt').val()
        let password = $('.input_pass').val()
        // 非空判断
        if (username.length == 0 || password.length == 0) {
            alert('请输入有效账号和密码')
            return
        }
        $.ajax({
            url: BigNews.user_login,
            type: 'post',
            dataType: 'json',
            data: {
                username: username,
                password: password
            },
            success: function (backData) {
                // console.log(backData);
                if (backData.code == 200) { //成功后执行
                    // alert(backData.msg)
                    //弹出模态框并修改p标签内容
                    $('.modal-body>p').text(backData.msg)
                    $('#myModal').modal()
                    //点击确定后执行
                    $('#myModal').on('hidden.bs.modal', function (e) {
                        //在本地储存令牌token
                        localStorage.setItem('token', backData.token)
                        window.location.href = './index.html'
                    })
                } else {
                    // alert(backData.msg)
                    $('.modal-body>p').text(backData.msg)
                    $('#myModal').modal()
                }
            }
        })
    })
})